home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / The World of Computer Software.iso / tvg103_s.zip / STYX.PAS < prev    next >
Pascal/Delphi Source File  |  1992-07-29  |  5KB  |  224 lines

  1. {************************************************}
  2. {                                                }
  3. {   Turbo Pascal 6.0                             }
  4. {   Turbo Vision Demo                            }
  5. {   Copyright (c) 1990 by Borland International  }
  6. {                                                }
  7. {************************************************}
  8.  
  9. unit Styx;
  10.  
  11. {$F+,O-,X+,S-,D+,L+}
  12.  
  13. { Graphics Styx demo }
  14.  
  15. interface
  16.  
  17. uses TvGraph, DemoCmds, Objects, App, Views, Drivers;
  18.  
  19. type
  20.   XYCord = record
  21.    XA,YA,XB,YB:integer;
  22.   end;
  23.   PStyx = ^TStyx;
  24.   TStyx = object(TView)
  25.     (* use as bit map *)
  26.     GraphWindowId:byte;
  27.     CurrentStick:byte;
  28.     Velocity:XYCord;
  29.     StyxLocations:Array[0..15] of XYCord;
  30.     constructor Init(Var Bounds:Trect);
  31.     destructor Done;virtual;
  32.     procedure Prod;
  33.     procedure Draw; virtual;
  34.     procedure GetGraphBounds(var R:GRect);
  35.     procedure GetGraphClipRect(var R:GRect);
  36.     procedure HandleEvent(var Event:TEvent); virtual;
  37.   end;
  38.  
  39.   PStyxDemo = ^TStyxDemo;
  40.   TStyxDemo = object(TWindow)
  41.     constructor Init;
  42.   end;
  43.  
  44. const
  45.   AsciiTableCommandBase: Word = 910;
  46.  
  47.   RStyx: TStreamRec = (
  48.      ObjType: 10090;
  49.      VmtLink: Ofs(TypeOf(TStyx)^);
  50.      Load:    @TStyx.Load;
  51.      Store:   @TStyx.Store
  52.   );
  53.   RStyxDemo: TStreamRec = (
  54.      ObjType: 10091;
  55.      VmtLink: Ofs(TypeOf(TStyxDemo)^);
  56.      Load:    @TStyxDemo.Load;
  57.      Store:   @TStyxDemo.Store
  58.   );
  59.  
  60. procedure RegisterStyx;
  61.  
  62. implementation
  63.  
  64. constructor TStyx.Init(Var Bounds:Trect);
  65. var
  66.  R:GRect;
  67. begin
  68.  TView.Init(Bounds);
  69.  CurrentStick:=0;
  70.  GrowMode:=gfGrowHiX+GfGrowHiY;
  71.  fillchar(StyxLocations,Sizeof(StyxLocations),#0);
  72.  (* Assume all available *)
  73.  GraphWindowId:=NextGraphId;
  74.  UseGraphId(GraphWindowId);
  75.  GetGraphBounds(R);
  76.  with Styxlocations[0] do
  77.  with R do
  78.  begin
  79.     XA:=(B.X-A.X) div 2;
  80.     YA:=(B.Y-A.Y) div 2;
  81.     XB:=(B.X-A.X) div 3;
  82.     YB:=(B.Y-A.Y) div 3;
  83.  end;
  84.  with Velocity do
  85.  begin
  86.     XA:=random(4)+1;if XA>2 then XA:=2-XA;
  87.     XA:=XA*16;
  88.     YA:=random(4)+1;if YA>2 then YA:=2-YA;
  89.     YA:=YA*16;
  90.     XB:=random(4)+1;if XB>2 then XB:=2-XB;
  91.     XB:=XB*16;
  92.     YB:=random(4)+1;if YB>2 then YB:=2-YB;
  93.     YB:=YB*16;
  94.  end;
  95. end;
  96.  
  97. procedure TStyx.GetGraphBounds(var R:GRect);
  98. begin
  99.   GetExtent(R);
  100.   MakeGlobal(R.A,R.A);
  101.   MakeGlobal(R.B,R.B);
  102.   TextToGraphics(R,R);
  103. end;
  104.  
  105. procedure TStyx.GetGraphClipRect(var R:GRect);
  106. begin
  107.   GetClipRect(R);
  108.   MakeGlobal(R.A,R.A);
  109.   MakeGlobal(R.B,R.B);
  110.   TextToGraphics(R,R);
  111. end;
  112.  
  113. procedure TStyx.Draw;
  114. var
  115.   Buf: TDrawBuffer;
  116.   Y: Integer;
  117.   Color: Byte;
  118.   R:TRect;
  119. begin
  120.   GetExtent(R);
  121.   MakeGlobal(R.A,R.A);
  122.   MakeGlobal(R.B,R.B);
  123.   Color := 255;
  124.   MoveChar(Buf, Char(GraphWindowId), Color, Size.X);
  125.   for Y:=0 to Size.Y-1 do
  126.     WriteLine(0, Y, Size.X, 1, Buf);
  127.   Prod;
  128. end;
  129.  
  130. procedure TStyx.Prod;
  131. const
  132.  StyxColor:array[0..15] of byte =(15,11,11,9,9,9,9,1,1,1,1,1,1,1,1,0);
  133. var
  134.  Count:byte;
  135.  Actual:byte;
  136.  R:GRect;
  137.  LS:byte;
  138.  XMax,YMax:word;
  139. begin
  140.  UseGraphId(GraphWindowId);
  141.  LS:=CurrentStick;
  142.  CurrentStick:=(CurrentStick+1) mod 16;
  143.  GetGraphBounds(R);
  144.  XMax:=R.B.X-R.A.X-1;
  145.  YMax:=R.B.Y-R.A.Y-1;
  146.  with Styxlocations[CurrentStick] do
  147.    with R do
  148.    begin
  149.       XA:=Styxlocations[LS].XA+Velocity.XA;
  150.       if (XA<0) or (XA>XMax) then
  151.       begin
  152.        Velocity.XA:=-Velocity.XA;
  153.        if XA<0 then XA:=0 else XA:=XMax
  154.       end;
  155.       XB:=Styxlocations[LS].XB+Velocity.XB;
  156.       if (XB<0) or (XB>XMax) then
  157.       begin
  158.        Velocity.XB:=-Velocity.XB;
  159.        if XB<0 then XB:=0 else XB:=XMax
  160.       end;
  161.       YA:=Styxlocations[LS].YA+Velocity.YA;
  162.       if (YA<0) or (YA>YMax) then
  163.       begin
  164.        Velocity.YA:=-Velocity.YA;
  165.        if YA<0 then YA:=0 else YA:=YMax
  166.       end;
  167.       YB:=Styxlocations[LS].YB+Velocity.YB;
  168.       if (YB<0) or (YB>YMax) then
  169.       begin
  170.        Velocity.YB:=-Velocity.YB;
  171.        if YB<0 then YB:=0 else YB:=YMax
  172.       end;
  173.    end;
  174.    for count:=0 to 15 do
  175.    begin
  176.     Actual:=(16-Count+CurrentStick) mod 16;
  177.     with Styxlocations[Count] do
  178.        DrawLine(R.A.X+XA,R.A.Y+YA,R.A.X+XB,R.A.Y+YB,StyxColor[Actual]);
  179.    end;
  180. end;
  181.  
  182. procedure TStyx.HandleEvent(var Event:TEvent);
  183. var
  184.   CurrentSpot: TPoint;
  185. begin
  186.   if (Event.What=evCommand) and (Event.Command=cmProdStyx) then
  187.   begin
  188.     Prod;
  189.     ClearEvent(Event);
  190.   end;
  191.   TView.HandleEvent(Event);
  192. end;
  193.  
  194. destructor TStyx.Done;
  195. begin
  196.  TView.Done;
  197.  ReleaseGraphId(GraphWindowId);
  198. end;
  199.  
  200. constructor TStyxDemo.Init;
  201. var
  202.   R: TRect;
  203.   Control: PVIew;
  204. begin
  205.   R.Assign(0, 0, 34, 12);
  206.   TWindow.Init(R, 'S T Y X', wnNoNumber);
  207. {  Flags := Flags and not (wfGrow + wfZoom);}
  208.   GetExtent(R);
  209.   R.Grow(-1,-1);
  210.   Control := New(PStyx, Init(R));
  211.   with Control^ do
  212.     Options := Options or ofFramed;
  213.   Insert(Control);
  214.   Control^.Select;
  215. end;
  216.  
  217. procedure RegisterStyx;
  218. begin
  219.   RegisterType(RStyx);
  220.   RegisterType(RStyxDemo);
  221. end;
  222.  
  223. end.
  224.